import {createRouter, createWebHashHistory} from 'vue-router'
import layout from '@/views/layout/index.vue'
import home from '../views/home/index.vue'
const router = createRouter({
  // history: createWebHashHistory(),
  routes:[
    {
      path:'/',
      component:layout,
      children:[
        {
          path:'',//默认的路由
          component:home
        },
        {
          path:'/category/:id',
          component:() => import('@/views/category/index.vue')
        },
        {
          path:'/category/sub/:id',
          component:() => import('@/views/category/sub.vue')
        },
        {
          path:'/goods/:id',
          component:() => import('@/views/goods/index.vue')
        },
      ]
    },
    
    {
      path:'/login',
      component:() => import('@/views/login/index.vue')
    },
    {
      path: '/login/callback',
      component: () => import('@/views/login/callback.vue')
    }
  ],
  history: createWebHashHistory(),
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部
    return { top: 0 }
  },
})
export default router